<template>
  <el-backtop :bottom="60"></el-backtop>
  <el-container class="home-container">
    <!--头部布局-->
    <el-header>
      <el-aside width="200px">
        <el-row type="flex" justify="center"> 数据管理面板 </el-row>
      </el-aside>
      <el-col :span="19">
        <div class="toggle-button" @click="toggleCollapase">
          <el-icon size="20px">
            <Fold />
          </el-icon>
        </div>
      </el-col>
      <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" circle
        @click="infoVisible = true" />
      <hr />
      <el-button type="danger" :icon="Close" circle @click="dialogVisible = true" style="align=right;" />
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <el-menu background-color="#0f0303" text-color="#fff" active-text-color="#409eff" unique-opened
          :collapse="isCollapse" :collapse-transition="false" :router="true" :default-active="$route.path">
          <el-menu-item index="/Info" key="0">
            <el-icon>
              <List />
            </el-icon>
            <template #title>信息总览</template>
          </el-menu-item>

          <el-sub-menu index="/management" key="1">
            <template #title>
              <el-icon>
                <Cloudy />
              </el-icon>
              <span>数据管理</span>
            </template>
            <el-menu-item-group title="第一分级">
              <el-menu-item index="/collegeInfo">
                <el-icon>
                  <House />
                </el-icon>学院
              </el-menu-item>
              <el-menu-item index="/majorInfo">
                <el-icon>
                  <Management />
                </el-icon>专业
              </el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="第二分级">
              <el-menu-item index="/classInfo">
                <el-icon>
                  <Monitor />
                </el-icon>班级
              </el-menu-item>
              <el-menu-item index="/studentInfo">
                <el-icon>
                  <Avatar />
                </el-icon>学生
              </el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="第三分级">
              <el-menu-item index="/questionInfo">
                <el-icon>
                  <Document />
                </el-icon>题目
              </el-menu-item>
              <el-menu-item index="/resultInfo">
                <el-icon>
                  <Filter />
                </el-icon>结果
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item index="/allInfo" key="2">
            <el-icon>
              <DataAnalysis />
            </el-icon>
            <template #title>数据可视化</template>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

  <el-dialog title="退出" v-model="dialogVisible" width="30%" draggable>
    <el-descriptions title="">
      <el-descriptions-item label="">
        <span>
          亲爱的管理员 {{ username }}，感谢您的使用，欢迎您再次登录 M B T I
          综合数据管理平台</span>
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="danger" @click="logout">退出登录</el-button>
        <el-button @click="dialogVisible = false">返回</el-button>
      </span>
    </template>
  </el-dialog>

  <el-dialog title="账号信息" v-model="infoVisible" width="20%" draggable>
    <el-row type="flex" justify="center">
      <el-avatar :size="120" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png">
      </el-avatar>
    </el-row>
    <br />
    <el-row type="flex" justify="center">
      <el-descriptions title="">
        <el-descriptions-item label="身份">
          <el-tag size="small">管理员</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-row>
    <el-row type="flex" justify="center">
      <el-descriptions title="">
        <el-descriptions-item label="账号">
          <el-tag size="small">{{ username }}</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-row>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="infoVisible = false">返回</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { Close } from "@element-plus/icons-vue";
export default {
  data() {
    return {
      isCollapse: false,
      dialogVisible: false,
      infoVisible: false,
      username: window.sessionStorage.getItem("username"),
      Close,
    };
  },
  created() {
    this.username = window.sessionStorage.getItem("username");
  },
  methods: {
    async logout() {
      const { data: res } = await this.$http.get("api/jwt/delete");
      window.sessionStorage.clear();
      console.log(res);
      this.$message.success("退出成功");
      this.$router.push("/");
    },

    toggleCollapase() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>

<style lang="less" scoped>
.el-header {
  background-color: #0f0303;
  display: flex;
  // justify-content: space-between;
  padding-left: 0%;
  align-items: center;
  color: #fff;
  font-size: 20px;

  >div {
    display: flex;
    align-items: center;

    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #0f0303;

  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.home-container {
  height: 100%;
}

.home-container .el-avatar {
  cursor: pointer;
}

.toggle-button {
  background-color: #0f0303;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: left;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
